In [56]:
import pandas as pd
from matplotlib.pyplot import pie, axis, show
%matplotlib inline
import matplotlib.pyplot as plt
In [4]:
fine_df_file = '../data/interim/fine_enriched_parking_violations.tsv'
In [91]:
df = pd.read_csv(fine_df_file, sep='\t', parse_dates=['ticket_issue_datetime'])
df['counter'] = 1
df['dmv_area'] = (df.rp_plate_state=='DC') | (df.rp_plate_state=='MD') | (df.rp_plate_state=='VA')
In [85]:
df.columns
Out[85]:
In [98]:
df['dmv_area'] = (df.rp_plate_state=='DC') | (df.rp_plate_state=='MD') | (df.rp_plate_state=='VA')
In [84]:
dmv_vs_other = df.groupby(df.dmv_area).counter.sum()#.reset_index()
# dmv_vs_other# .name('Parking Tickets Jan 2009 - May 2016')
dmv_vs_other = pd.Series(dmv_vs_other, name='Parking Tickets Volume % ~ Jan 2009 - May 2016')
dmv_vs_other.plot.pie(labels=['Not DMV', 'DMV'], colors=['r', 'y'], autopct='%.2f', figsize=(4, 4))
Out[84]:
In [80]:
dmv_vs_other = df.groupby(df.dmv_area).fine.sum()#.reset_index()
# dmv_vs_other# .name('Parking Tickets Jan 2009 - May 2016')
dmv_vs_other = pd.Series(dmv_vs_other, name='Parking Ticket Fine Percent ~ Jan 2009 - May 2016')
dmv_vs_other.plot.pie(labels=['Not DMV', 'DMV'], colors=['r', 'y'], autopct='%.2f', figsize=(4, 4))
Out[80]:
In [108]:
dates = pd.date_range(df.ticket_issue_datetime.min(), df.ticket_issue_datetime.max(), freq='Q')
In [161]:
dmv_datetime = df[["ticket_issue_datetime", 'dmv_area', 'fine', 'counter']]
dmv_datetime.set_index("ticket_issue_datetime", inplace=True)
three_month_groups = dmv_datetime.groupby(pd.TimeGrouper('3M')).apply(lambda x: x.groupby('dmv_area').sum())
In [150]:
total_by_6month = dmv_datetime.groupby(pd.TimeGrouper('6M')).sum()
total_by_6month
Out[150]:
In [171]:
total_by_6month.counter.plot(kind='bar', title="Volume of Tickets for All DMV States in DC")
plt.xlabel('6 Month Period')
plt.ylabel('Total Number Traffic Tickets')
Out[171]:
In [ ]:
In [180]:
year_period = dmv_datetime.groupby(pd.TimeGrouper('12M')).apply(lambda x: x.groupby('dmv_area').sum())
year_period#.plot(kind='bar', title="Volume of Tickets for All DMV States in DC")
Out[180]:
In [ ]: